function bindEvents(bindings) {
    for (var i in bindings) {
        if (bindings[i].selector) {
            $$(bindings[i].element).on(bindings[i].event, bindings[i].selector, bindings[i].handler);
        } else {
            $$(bindings[i].element).on(bindings[i].event, bindings[i].handler);
        }
    }
}

var batchQuery = {
    provinceId: xhr.getSearch('provinceId') || 1,
    initialize: function () {
        var provinceName = xhr.getSearch('provinceName')
        $$('.test').html(provinceName)
        this.getInitData()
        this.bindEvent()
    },
    getInitData: function () {
        myApp.showIndicator();

        this.reqXinchou()

    },
    reqBenke() {
        xhr.benke(function (res) {
            var output = tplManager.renderTplById('tplBenke', res.data)
            $$('#rank-list').html(output)
        })
    },
    reqZhuanke() {
        xhr.zhuanke(function (res) {
            var output = tplManager.renderTplById('tplBenke', res.data)
            $$('#rank-list').html(output)
        })
    },
    reqGril() {
        xhr.gril(function (res) {
            var output = tplManager.renderTplById('tplGril', res.data)
            $$('#rank-list').html(output)
        })
    },
    reqMajorsalary() {
        xhr.majorsalary(function (res) {
            var output = tplManager.renderTplById('tplMajorsalary', res.data)
            $$('#rank-list').html(output)
        })
    },
    reqXinchou() {
        xhr.xinchou(function (res) {
            var output = tplManager.renderTplById('tplXinchou', res.data)
            $$('#rank-list').html(output)
        })
    },
    reqCompete() {
        xhr.compete(function (res) {
            var output = tplManager.renderTplById('tplCompete', res.data)
            $$('#rank-list').html(output)
        })
    },
    reqEmployee() {
        xhr.employee(function (res) {
            var output = tplManager.renderTplById('tplEmployee', res.data)
            $$('#rank-list').html(output)
        })
    },
    bindEvent: function () {
        var bindings = [
            {
                'element': '.page',
                'event': 'click',
                'selector': '.test',
                'handler': this.openPop()
            }, {
                'element': '.pages',
                'event': 'click',
                'selector': '#province li',
                'handler': this.selectProvince()
            }, {
                'element': '.pages',
                'event': 'click',
                'selector': '.close-picker',
                'handler': this.switchImg()
            }
        ];
        utils.bindEvent(bindings);
    },
    switchImg: function () {
        return function (event) {
            $$('.switch-img').attr('src', './img/down.png')
        }
    },
    openPop: function () {
        return function (event) {
            $$('.switch-img').attr('src', './img/up.png')
            myApp.pickerModal('.picker-info')
        }
    },
    selectProvince() {
        var self = this
        return function (event) {
            var id = $$(this).data('id'),
                text = $$(this).data('text')

            if (id === 'benke') {
                self.reqBenke()
            } else if (id === 'zhuanke') {
                self.reqZhuanke()
            } else if (id === 'gril') {
                self.reqGril()
            } else if (id === 'major') {
                self.reqMajorsalary()
            } else if (id === 'salary') {
                self.reqXinchou()
            } else if (id === 'compete') {
                self.reqCompete()
            } else if (id === 'employee') {
                self.reqEmployee()
            }

            $$('.test').html(text)
            $$('.switch-img').attr('src', './img/down.png')
            myApp.closeModal('.picker-info')
        }
    }
}
batchQuery.initialize()